public class VIPCenter {
    //抽象策略
    private ServiceHandler serviceHandler;

    //构造函数设置具体策略
    public VIPCenter(ServiceHandler serviceHandler) {
        this.serviceHandler = serviceHandler;
    }

    /**
     * Context封装角色
     * 封装后的策略方法
     */
    public void serviceVIP(BaseUser user) {
        this.serviceHandler.service(user);
    }


    /**
     * user共同属性
     */
    static class BaseUser {
        private String desc;

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }
        //do something
    }


    /**
     * 穷逼user，送的那种
     */
    static class SlumDogVIP extends BaseUser {
        //do something
    }


    /**
     * 正儿八经买vip的user
     */
    static class RealVIP extends BaseUser {
        //do something
    }


    /**
     * 可以为所欲为的VIP
     */
    static class SuperVip extends BaseUser {

    }


    /**
     * Strategy抽象策略角色
     */
    interface ServiceHandler {
        void service(BaseUser user);
    }


    /**
     * 具体策略(ConcreteStrategy)角色
     * 处理穷逼VIP
     */
    static class SlumDogVIPServiceHandler implements ServiceHandler {
        @Override
        public void service(BaseUser user) {
            System.out.println("该用户是：" + user.getDesc());
            System.out.println("穷逼");
        }
    }


    /**
     * 具体策略(ConcreteStrategy)角色
     * 处理正常的VIP
     */
    static class RealVIPServiceHandler implements ServiceHandler {
        @Override
        public void service(BaseUser user) {
            System.out.println("该用户是：" + user.getDesc());
            System.out.println("正常人");
        }
    }


    public static void main(String[] args) {
        //声明一个具体的策略
        ServiceHandler serviceHandler1 = new SlumDogVIPServiceHandler();
        BaseUser user1 = new SlumDogVIP();
        user1.setDesc("穷逼");
        //声明一个上下文对象
        VIPCenter vipCenter1 = new VIPCenter(serviceHandler1);
        //执行封装后的方法
        vipCenter1.serviceVIP(user1);

        serviceHandler1 = new RealVIPServiceHandler();
        user1 = new RealVIP();
        user1.setDesc("正常");

        vipCenter1 = new VIPCenter(serviceHandler1);
        vipCenter1.serviceVIP(user1);


    }
}
